package chapter2;

import util.PrintUtils;

/**
 * number add
 */
public class IntegerSum4 {
    public int[] sum(int[] arr1, int[] arr2, int n) {
        int[] arr3 = new int[n+1];
        int carryBit = 0;
        for (int i = n-1; i >= 0; i--) {
            int sum = arr1[i] + arr2[i] + carryBit;
            arr3[i+1] = sum % 10;
            carryBit = sum / 10;
        }
        arr3[0] = carryBit;
        return arr3;
    }

    public static void main(String[] args) {
        int[] arr1 = {2,7,7};
        int[] arr2 = {9,3,9};
        PrintUtils.PrintArrayNumber(new IntegerSum4().sum(arr1, arr2, 3));
    }
}
